package com.example.eureka_client.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.client.discovery.DiscoveryClient;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.logging.Logger;

/**
 * @Description: <p>
 * Company: aspire
 * </p>
 * @Author: gjj
 * @Date: 2019/6/28
 */
@RestController
public class HelloController {

    private final Logger logger = Logger.getLogger(getClass().getName());

    @Autowired
    private DiscoveryClient client;

    @RequestMapping("hello")
    public String hello(){
        List<String> services = client.getServices();

        services.stream().flatMap(a->client.getInstances(a).stream()).forEach(
                a->logger.info("/hello, host:"+a.getHost()+", service_id:"+ a.getServiceId()));

        return "Hello World";
    }

    @RequestMapping("helloTimeOut")
    public String helloTimeOut(){
        logger.info("进入helloTimeOut方法");
        try {
            Thread.sleep(10000L);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        return "虽然等待那么久，但还是返回了数据";
    }
}
